home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programmer Power Tools
/
Programmer Power Tools.iso
/
progjrn
/
pj_6_6.arc
/
NDPC386.ARC
/
CLOCK.ASM
next >
Wrap
Assembly Source File
|
1988-09-01
|
3KB
|
101 lines
;
; CLOCK.ASM
;
; Author: M. Steven Baker
; Date: September 1, 1988
;
; a clock function for NDP C-386
; must assemble with Phar LAP 386asm
; C calling convention returning 1/100 seconds since midnite as a long
;
; long t;
; t = clock();
.386 ; required to generate 32-bit code/data
; It is very important when linking to F77L-EM/32 program units that any data
; segments your assembly code uses have their class name as 'DATA' in order
; to link correctly. In addition, you must also use the GROUP directive
; to include the data in group DGROUP. DS and ES are set to DGROUP by the
; FORTRAN code, and must be set that way on return. Your code segment must
; also be included in the group CGROUP, and include the directive:
; ASSUME DS:DGROUP, CS:CGROUP
dataseg segment dword
dataseg ends
;
codeseg segment dword er public use32
assume cs:codeseg, ds:dataseg
;
; The procedure names must be declared public to be addressable by
; other modules.
;
public _clock
align 4
_clock proc near
;
; Upon entry to any function, NDP C-386 has pushed arguments
; onto the stack. When all arguments have been dealt with,
; NDPF-386 issues a near call to the named routine.
;
; log4 = example( int2, int4, int2a, int2a(3), dp, cmpx )
; arg1 arg2 arg3 arg4 arg5 arg6
;
; push ebp ; always do this... if EBP/ESP are used
; mov ebp, esp ; and this (ebp must be preserved)
;
; The arguments are pushed right to left; thus, the first argument
; is closest to ebp. At this point, the stack contains:
;
; offset of argn
; ...
; offset of arg1 = IHR
; return code offset (EIP) }-- four byte address from near call
; saved ebp <-- ebp, esp
;
; The first argument address is now 8 bytes from ebp, referenced at [ebp+8].
; Note that the minimum argument displacement is 8 for subroutines and 12
; for functions.
;
; t = clock();
;
mov ah,2ch ;DOS Get Time function
int 21h ;returns CH=hour, CL=minute
; DH =second DL=hundredths
; ;note this trashes CX and DX
; mov eax,60
; mul ch
movzx eax,ch ;start with hours
lea eax,[eax+eax*4] ; x 5 use some fast integer multiplies
lea eax,[eax*4] ; x 20
lea eax,[eax+eax*2] ; x 60
;
movzx ecx,cl ; zero top of register
add eax,ecx ; now add in minutes
lea eax,[eax+eax*4] ; x 5 use some fast integer multiplies
lea eax,[eax*4] ; x 20
lea eax,[eax+eax*2] ; x 60
;
movzx ecx,dh
add eax,ecx ; add in seconds
lea eax,[eax+eax*4] ; x 5 use some fast integer multiplies
lea eax,[eax*4] ; x 20
lea eax,[eax+eax*4] ; x 100
movzx ecx,dl
add eax,ecx ;now add in hundredths of seconds
;
ret
_clock endp
codeseg ends
end
;
; Do not put any label name or expression after the end statement! This
; defines a program entry point, which has already been defined by the
; Fortran MAIN module.